
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * testSundial.java Test SundialMath.java calculation
 *
 * @author Arun Lee, Michael Terada, Marek Lopez
 */
public class testSundial {

    private SundialMath test;

    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
    }

    @AfterClass
    public static void tearDownAfterClass() throws Exception {
    }

    @Before
    public void setUp() throws Exception {
        test = new SundialMath();
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void test() {
        double[] HL;

        test.setInputs(21.3114, -157.7964, "2013/04/17");
        //	assertTrue(assertType(test.getGnomon()));		//check if we are getting double for gnomon angle

        //The following tests will check if the corrections are applied correctly using noon as a guide

        test.setInputs(-20.0559, 46.9336, "2011/01/01");
        assertTrue(test.getGnomon() > 0);		//check when latitude is negative do we still get positive gnomon angle, always true
        HL = test.getHourLines();
        assertTrue(HL[12] != 0.0);			    //check if both corrections applied

        //latitude 39.732, longitude -105 is Denver's coordinate since it is in the center of the time zone only EOT will apply
        test.setInputs(39.732, -105, "2013/02/12");		//Feb 12 is when the sundial time behind the most
        HL = test.getHourLines();
        assertTrue(HL[12] != 0.0 && HL[12] > 0);		//we need to add to tell the standard time so noon must be positive

        test.setInputs(39.732, -105, "2013/11/03");		//Nov 11 is when sundial time ahead the most
        HL = test.getHourLines();
        assertTrue(HL[12] != 0.0 && HL[12] < 0);		//we need to subtract to tell standard time so noon must be negative

        test.setInputs(39.732, -105, "2013/04/15");		//Apr 15 is when the equation of time is near zero
        HL = test.getHourLines();
        assertTrue(HL[12] > -0.1 || HL[12] < 0.1);		//check if close to zero

        test.setInputs(39.732, -105, "2013");		//check if 12 noon is at 0 when both corrections were not applied
        HL = test.getHourLines();
        assertTrue(HL[12] == 0.0);

        test.setInputs(400, 400, "A");				//test if enter wrong latitude, longitude and date
        HL = test.getHourLines();
        for (int i = 0; i < HL.length; i++) {
            assertTrue(HL[i] == 0.0);				//check all hour line's angle are 0
        }
        assertTrue(test.getGnomon() == 0.0);		//gnomon should be 0 as latitude is invalid
    }

    /**
     * assertType - type check
     *
     * @param type - the class o - the variable
     * @return boolean
     */
    public boolean assertType(Class<?> type, Object o) {
        boolean check = false;
        if (type.isInstance(o)) {
            check = true;
        } else {
            check = false;
        }
        return check;
    }
}
